<?php
/**
 * design pattern 之 单例模式 singleton
 */
class Singleton
{
    private static $instance;

    private function __construct(){}

    private function __clone(){}

    private function __wakeup(){}

    public static function getInstance()
    {
        if (static::$instance == null) {
            static::$instance = new static();
        }

        return static::$instance;
    }
}

$s1 = Singleton::getInstance(); // object(Singleton)#1 (0) { }
$s2 = Singleton::getInstance(); // object(Singleton)#1 (0) { }
var_dump($s1, $s2);